pass by reference behavior with openCV

by: skypickle, 9 years ago


I repeated Harrison's lesson 5 with TWO copies of the base image as a target.

Basically, I start out with
img1 = cv2.imread('3D-Matplotlib.png')
img1a = cv2.imread('3D-Matplotlib.png')

I do different manipulations to each.

Then I show them

cv2.imshow('r1',img1)
cv2.imshow('r3',img1a)

I see two different images. But if I start with

img1 = cv2.imread('3D-Matplotlib.png')
img1a = img1

and I end up showing two identical images.
This is vexing.
Even though I did totally different stuff to img1a, when I show it with
cv2.imshow('r3',img1a)
it is as if I just said
cv2.imshow('r3',img1)

Here is the full code and the question on SO:
http://stackoverflow.com/questions/36610560/is-this-pythons-pass-by-reference-behavior

This is sneaky behavior. I might set a variable X to some quantity,Q. Then I do stuff to Q and do different stuff to X. But all that work on X is not shown. Instead, when I show that variable,X, I get the work that was done to Q, the variable it was INITIALLY assigned to!

Does this happen often in openCV and Python?



You must be logged in to post. Please login or register an account.